import { Injectable } from '@angular/core';
import { ApolloQueryResult, FetchResult } from '@apollo/client/core';
import { Apollo, gql, QueryRef } from 'apollo-angular';
import { Observable } from 'rxjs';
import { NamesVisitorRecordServiceApi,
NamesVisitorRecordService_listResult,
NamesVisitorRecordService_listVariables,
NamesVisitorRecordService_totalCountResult,
NamesVisitorRecordService_searchResult,
NamesVisitorRecordService_searchVariables,
NamesVisitorRecordService_loadAllResult,
NamesVisitorRecordService_getByIdResult,
NamesVisitorRecordService_getByIdVariables,
NamesVisitorRecordService_saveResult,
NamesVisitorRecordService_saveVariables,
NamesVisitorRecordService_removeByIdResult,
NamesVisitorRecordService_removeByIdVariables,
NamesVisitorRecordService_removeByIdListResult,
NamesVisitorRecordService_removeByIdListVariables,
NamesVisitorRecordResultInfo, NamesVisitorRecordPageInfo,
NamesVisitorRecordConnection,
NamesVisitorRecordPackage,
NamesVisitorRecordOrderBy,
NamesVisitorRecordMutationInfo,
NamesVisitorRecordStringFilter,
NamesVisitorRecordNumberFilter,
NamesVisitorRecordBooleanFilter,
namesVisitorRecordServiceQuery,
namesVisitorRecordServiceMutation,
NamesVisitorRecordServiceQueryOptions,
NamesVisitorRecordStore,
NamesVisitorRecordView,
NamesVisitorRecordInput,
NamesVisitorRecordFilter,
NamesVisitorRecordErrorBody} from '../model/names_visitor_record_service.model';

/************************************************************************
 * 资源访问日志
 */
@Injectable({
    providedIn: 'root'
})
export class NamesVisitorRecordService implements NamesVisitorRecordServiceApi {

        private listGql:string;
        private totalCountGql:string;
        private searchGql:string;
        private searchObjectRef: QueryRef<NamesVisitorRecordService_searchResult>;
        private loadAllGql:string;
        private getByIdGql:string;

    constructor(private apollo: Apollo) {
        this.listGql=`query nars_namesVisitorRecordService_list($filter: NamesVisitorRecordFilter!,$orderBy: OrderBy){${namesVisitorRecordServiceQuery.namesVisitorRecordService_list}}`;
        this.totalCountGql=`query nars_namesVisitorRecordService_totalCount{${namesVisitorRecordServiceQuery.namesVisitorRecordService_totalCount}}`;
        this.searchGql=`query nars_namesVisitorRecordService_search($first: Int!,$offset: Float!,$filter: NamesVisitorRecordFilter!,$orderBy: OrderBy){${namesVisitorRecordServiceQuery.namesVisitorRecordService_search}}`;
        this.searchObjectRef = apollo.watchQuery<NamesVisitorRecordService_searchResult>({ query: gql`${this.searchGql}`, fetchPolicy:'cache-first' });
        this.loadAllGql=`query nars_namesVisitorRecordService_loadAll{${namesVisitorRecordServiceQuery.namesVisitorRecordService_loadAll}}`;
        this.getByIdGql=`query nars_namesVisitorRecordService_getById($id: String!){${namesVisitorRecordServiceQuery.namesVisitorRecordService_getById}}`;
    }
    /**
     * 分页查询
     */
    list(variables: NamesVisitorRecordService_listVariables, options:NamesVisitorRecordServiceQueryOptions = { cachePolicy: 'no-cache', more: false }): Observable<ApolloQueryResult<NamesVisitorRecordService_listResult>> {
            return this.apollo.query({ query: gql`${this.listGql}`,variables ,fetchPolicy:options.cachePolicy});
    }
    /**
     * 统计库中所有对象的数据量
     */
    totalCount(options:NamesVisitorRecordServiceQueryOptions = { cachePolicy: 'no-cache', more: false }): Observable<ApolloQueryResult<NamesVisitorRecordService_totalCountResult>> {
            return this.apollo.query({ query: gql`${this.totalCountGql}`,fetchPolicy:options.cachePolicy});
    }
    /**
     * 游标查询
     */
    search(variables: NamesVisitorRecordService_searchVariables, options:NamesVisitorRecordServiceQueryOptions = { cachePolicy: 'cache-first', more: false }): Observable<ApolloQueryResult<NamesVisitorRecordService_searchResult>> {
        this.searchObjectRef.setVariables(variables);
        if(options.more){
            this.searchObjectRef.fetchMore({variables});
        }
        return this.searchObjectRef.valueChanges;
    }
    /**
     * 获取库中所有数据，数据量大时请谨慎使用
     */
    loadAll(options:NamesVisitorRecordServiceQueryOptions = { cachePolicy: 'cache-first', more: false }): Observable<ApolloQueryResult<NamesVisitorRecordService_loadAllResult>> {
            return this.apollo.query({ query: gql`${this.loadAllGql}`,fetchPolicy:options.cachePolicy});
    }
    /**
     * 获取一个对象
     */
    getById(variables: NamesVisitorRecordService_getByIdVariables, options:NamesVisitorRecordServiceQueryOptions = { cachePolicy: 'cache-first', more: false }): Observable<ApolloQueryResult<NamesVisitorRecordService_getByIdResult>> {
            return this.apollo.query({ query: gql`${this.getByIdGql}`,variables ,fetchPolicy:options.cachePolicy});
    }
    /**
     * 保存对象
     */
    save(variables: NamesVisitorRecordService_saveVariables): Observable<FetchResult<NamesVisitorRecordService_saveResult>>{
        return this.apollo.mutate({mutation: gql`mutation nars_namesVisitorRecordService_save($entity: NamesVisitorRecordInput!){${namesVisitorRecordServiceMutation.namesVisitorRecordService_save}}`, variables,fetchPolicy:'no-cache'});
    }
    /**
     * 删除一个对象
     */
    removeById(variables: NamesVisitorRecordService_removeByIdVariables): Observable<FetchResult<NamesVisitorRecordService_removeByIdResult>>{
        return this.apollo.mutate({mutation: gql`mutation nars_namesVisitorRecordService_removeById($id: String!){${namesVisitorRecordServiceMutation.namesVisitorRecordService_removeById}}`, variables,fetchPolicy:'no-cache'});
    }
    /**
     * 删除一批对象
     */
    removeByIdList(variables: NamesVisitorRecordService_removeByIdListVariables): Observable<FetchResult<NamesVisitorRecordService_removeByIdListResult>>{
        return this.apollo.mutate({mutation: gql`mutation nars_namesVisitorRecordService_removeByIdList($ids: [String]!){${namesVisitorRecordServiceMutation.namesVisitorRecordService_removeByIdList}}`, variables,fetchPolicy:'no-cache'});
    }









}
